package com.itheima.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

//@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {

    /**
     * 设置资源映射
     * @param registry
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 什么样的地址，去什么样的路径里面找文件
        registry.addResourceHandler("/backend/**").addResourceLocations("classpath:/backend/");
        registry.addResourceHandler("/front/**").addResourceLocations("classpath:/front/");
    }

    /**
     * 复写扩展的消息转换器，把我们的转化的规则放进去！
     * @param converters
     */
    @Override
    protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {

        //1. 构建一个转换器
        MappingJackson2HttpMessageConverter mc = new MappingJackson2HttpMessageConverter();

        //2. 设置这个转换器的转换规则
        mc.setObjectMapper(new JacksonObjectMapper());

        //3. 把我们的转换器放置到集合当中。
        converters.add(0 , mc);

    }
}
